/**
 * Created by zhuyufeng on 2016/1/1.
 */
var loudongStore = Ext.create('Ext.data.Store', {
	fields: ['loudong'],
	data : [
		{"loudong":"东1"},{"loudong":"东2"},{"loudong":"东3"},{"loudong":"东4"},
		{"loudong":"东5"},{"loudong":"东6"},{"loudong":"东7"},{"loudong":"东8"},
		{"loudong":"东9"},{"loudong":"东10"},{"loudong":"东11"},{"loudong":"东12"}
	]
});

var loudong = new Ext.form.ComboBox({
	fieldLabel: '请选择楼栋',
	store: loudongStore,
	valueField: 'loudong',
	tpl: Ext.create('Ext.XTemplate',
		'<tpl for=".">',
		'<div class="x-boundlist-item">{loudong}</div>',
		'</tpl>'
	),
	displayTpl: Ext.create('Ext.XTemplate', 		// template for the content inside text field
		'<tpl for=".">',
		'{loudong}',
		'</tpl>'
	)
});

Ext.define('NoSupplyModel', {
	extend: 'Ext.data.Model',
	fields: [ 'id', 'number']
});
var NoSupplyStore = Ext.create('Ext.data.Store', {
	storeId:'gridStore',
	model: 'NoSupplyModel',
	autoLoad: true,
	pageSize: 4,
	proxy: {
		type: 'ajax',
		url : './json/nosupply',
		reader: {
			type: 'json',
			root: 'rows',
			totalProperty: 'total'
		}
	}
});
var NoSupplygrid = Ext.create('Ext.grid.Panel', {
	store: NoSupplyStore,
	height:410,
	forceFit:true,
	selType:'checkboxmodel',
	selModel: new Ext.selection.CheckboxModel({
		injectCheckbox:0,//checkbox位于哪一列，默认值为0
		mode:'simple',//multi,simple,single；默认为多选multi
		allowDeselect:true,//如果值true，并且mode值为单选（single）时，可以通过点击checkbox取消对其的选择
		checkOnly:false,//当checkOnly的值为true时只能从前面的复选框来选中本行，为false则可以
		enableKeyNav:false,
		listeners: {
			deselect: function (model, record, index) {//取消选中时产生的事件
			},
			select: function (model, record, index) {//record被选中时产生的事件
				//record.get('name');//选中的节目名称
			},
			selectionchange: function (model, selected) {//选择有改变时产生的事件
				var records = model.getSelection();
				if (records != '') {
					for (var i in records) {
						records[i].get('name')//选中的节目名称（方法一）
					}
				}
				if (selected != '') {
					//for (var p in selected) {
					//    if(Ext.get('delBtn').click()) {//如果点击删除按钮
					//        arryGrid.store.remove(selected[p]);
					//    }
					//}
				}
				sel = selected;
			}
		}
	}),
	columns: [
		{text: '寝室号',width: 100,dataIndex: 'id'},
		{text: '数量',	width: 150,dataIndex: 'number'}
	],
	dockedItems:[{
		xtype:'pagingtoolbar',
		store:NoSupplyStore,
		dock:'bottom',
		displayInfo:true,
		displayMsg:'第{0}条到第{1}条,一共{2}条',
		emptyMsg:'没有记录'
	}],
	tbar:[{
		xtype:'button',
		text:'标记为已送水'
	}]
});

var NoSupply = new Ext.Panel({
	title:'未送水',
	items:[loudong,NoSupplygrid]
})